//处理首页折线(功能测试、系统测试、体验测评)
import type { EChartsOption } from 'echarts';
import theme from '../config/theme.json';
//首页-静态折线图
// 返回折线图的默认配置
export function getLineDefaultOptions(): any {
  return {
    // 提示框
    tooltip: {
      // show:true,
      trigger: 'axis',
      axisPointer: {
        //显示放大轴线
        type: 'cross',
      },
      //文字靠左对齐
      textStyle: {
        align: 'left',
      },
      backgroundColor: 'rgba(255, 255, 255, 0.8)',
    },
    // 指示线显示内容
    axisPointer: {
      // link: { xAxisIndex: 'all' },
      label: {
        backgroundColor: '#777',
      },
    },
    // title
    legend: {
      icon: 'circle',
      itemWidth: 5, //每个图标的宽度
      itemHeight: 14,
      itemGap: 20,
      right: '0.5%',
      selectorPosition: 'start',
      selectorButtonGap: 1, //与图例之间的距离
      selectorLabel: {
        fontSize: 14,
        color: '#fff',
        backgroundColor: 'rgb(0,190,122)',
        borderColor: '#fff',
      },
      selector: [
        {
          type: 'selector',
          title: '全部',
        },
      ],
    },
    grid: {
      left: '1%',
      right: '0.5%',
      bottom: 20, //显示横坐标距离下面的位置
      containLabel: true,
    },
    xAxis: {
      type: 'category',
      //坐标轴两边留白策略，false不留白
      // boundaryGap: false,
      //默认取消纵轴线，去除网格线
      splitLine: {
        show: false,
      },
      axisLine: {
        //增加x坐标轴
        show: false,
        lineStyle: {
          //修改x坐标轴颜色
          // color: '#888888',
          // width: 0.5,
        },
      },

      nameTextStyle: {
        fontFamily: 'DIN 2014',
      },
      //x轴左右偏移设置
      // axisLabel: {
      //   padding: [0, 0, 0, 80],
      // },
    },
    yAxis: {
      type: 'value',
      // offset: 20,
      axisLine: {
        //是否显示坐标轴轴线。
        show: false,
        lineStyle: {
          //修改y坐标轴颜色
          color: '#888888',
        },
      },
      splitLine: {
        show: true,
        lineStyle: {
          type: 'dashed',
        },
      },
      //坐标轴刻度标签的相关设置
      axisLabel: {
        show: true,
        interval: 'auto',
        formatter: '{value} %',
      },
    },
  };
}
//处理折线阴影
export function getBaseline({ color, options }) {
  return {
    type: 'line',
    symbol: 'circle',
    symbolSize: 6,
    areaStyle: {
      color: {
        type: 'linear',
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [
          {
            offset: 0,
            color: color,
          },
          {
            offset: 1,
            color: color + '00',
          },
        ],
      },
    },
    ...options,
  };
}
export function getLineBarMixedDefaultOptions(): EChartsOption {
  return {
    tooltip: {
      show:true,
      trigger: 'axis',
      textStyle: {
        align: 'left',
      },
      axisPointer: {
        type: 'cross',
        crossStyle: {
          color: '#999',
        },
      },
    },
    legend: {
      // icon: 'circle',
      itemWidth: 5, //每个图标的宽度
      itemHeight: 14,
      itemGap: 20,
      right: '0.5%',
    },
    grid: {
      left: 'left',
      right: '0%',
      bottom: 20, //显示横坐标距离下面的位置
      containLabel: true,
    },
    xAxis: {
      type: 'category',
      axisLine: {
        show: false,
      },
      splitLine: {
        show: false,
      },
    },
    toolbox:{
      show:true
    },
    yAxis: [],
    series: [],
  };
}
export function setGradientsSeries(series: any): any {
  if (!series) return [];
  // 打印获取到的图表的series
  console.log('打印获取到的图表的series',series);
  
  if (Array.isArray(series)) {
    return series.map((item, i) => getBaseline({ color: theme.color[i], options: item }));
  } else {
    return [getBaseline({ color: theme.color[0], options: series })];
  }
}
